﻿using System.Diagnostics;

using Microsoft.Extensions.Logging;

using zijian666.WorkScheduler.Abstractions;

class MyWorkHandler(ILogger<MyWorkHandler>? logger) : IWorkHandler
{
    private readonly ILogger<MyWorkHandler>? _logger = logger;

    public async Task Execute(IWorkContext context)
    {
        var total = (int)context.Data.Arguments!;
        var sw = Stopwatch.StartNew();

        while (sw.ElapsedMilliseconds < total)
        {
            await Task.Delay(100);
            await context.Report(sw.ElapsedMilliseconds / total, $"已经执行了 {sw.ElapsedMilliseconds} ms");
        }

        await context.Success("成功", "成功");
        _logger?.LogDebug(context.Data.Id + " 执行成功");
    }

}